package com.example.oms.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {
    private static String key = "123456";
    private static long life = 3600*1000;
    public static String GenerateJwt(Map<String,Object> claims){
        return  Jwts.builder()
                    .signWith(SignatureAlgorithm.HS256,key)
                    .setClaims(claims)
                    .setExpiration(new Date(System.currentTimeMillis() + life))//有效期1h
                    .compact();
    }
    public static Map<String,Object> ParseJwt(String jwt){
        return  Jwts.parser()
                    .setSigningKey(key)
                    .parseClaimsJws(jwt)
                    .getBody();
    }
}
